package com.hundsun.fcp.adapter;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.hundsun.fcp.R;
import com.hundsun.fcp.bean.ActionBean;
import com.hundsun.fcp.bean.BannerBean;
import com.hundsun.fcp.common.utils.DisplayImageOptionsUtil;
import com.nostra13.universalimageloader.core.ImageLoader;

public class IconAdapter extends PagerAdapter {
	private List<BannerBean> mData;
	private final Map<Integer, View> map = new HashMap();
	private Context mContext;

	public IconAdapter(Context pContext){
		mContext = pContext ;
	}
	
	@Override
	public int getCount() {
		return mData==null?0:mData.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return false;
	}
	
	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		View _View = (View)this.map.get(Integer.valueOf(position));
		if (_View == null)
	    {
			_View = View.inflate(this.mContext, 2130903189, null);
			_View.setPadding(0, 0, 0, 0);
			map.put(position, _View);
			ImageView _ImageView = (ImageView)_View.findViewById(R.id.imageview);
			_ImageView.setTag(mData.get(position));
			_ImageView.setOnClickListener(new OnClickListener() {
				@Override
				public void onClick(View v) {
					ActionBean _ActionBean = (ActionBean)v.getTag();
					//执行动画动作
				}
			}) ;
			
			ImageLoader imageLoader = ImageLoader.getInstance() ;
			imageLoader.displayImage(null, _ImageView, DisplayImageOptionsUtil.adImageOptions()) ;
	    }
		container.addView(_View) ;
		return _View ;
	}
	
	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View)object);
	}

	public void setData(List<BannerBean> pActionBeans)
	{
	    mData = pActionBeans;
	    map.clear();
	}
}
